<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改库存')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-stock-edit" th:object="${chainStock}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品ID：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="commodityId" name="commodityId" type="hidden" th:value="*{commodityId}"/>
                    <input class="form-control" disabled type="text" onclick="selectCommodityIdRadio()"
                           id="commodityName"
                           readonly="true" th:value="*{commodityName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品图片：</label>
            <div class="col-sm-8">
                <img th:src="*{image}" width="150" height="100">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">库存数量：</label>
            <div class="col-sm-8">
                <input name="quantity" th:field="*{quantity}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">进货价格：</label>
            <div class="col-sm-8">
                <input name="purchasePrice" th:field="*{purchasePrice}" class="form-control" type="text" required readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">建议零售价：</label>
            <div class="col-sm-8">
                <input name="retailPrice" th:field="*{retailPrice}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">摆放位置：</label>
            <div class="col-sm-8">
                <input name="position" th:field="*{position}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <select name="status" class="form-control m-b" th:with="type=${@dict.getType('stock_status')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{status}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "chain/stock";
    var commodityPrefix = ctx + "chain/commodity";
    $("#form-stock-edit").validate({
        focusCleanup: true
    });

    function selectCommodityIdRadio() {
        var options = {
            title: '选择商品',
            url: commodityPrefix + "/selectCommodity",
            callBack: doCommoditySubmit
        };
        $.modal.openOptions(options);
    }


    function doCommoditySubmit(index, layer) {
        var body = $.modal.getChildFrame(index);
        $("#commodityId").val(body.find("#commodityId").val());
        $("#commodityName").val(body.find("#commodityName").val());
        var purchasePrice = body.find("#retailPrice").val();
        $("#purchasePrice").val(purchasePrice);
        $("#retailPrice").val(parseInt(purchasePrice) + 100);

        $.modal.close(index);
    }

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-stock-edit').serialize());
        }
    }

</script>
</body>
</html>